/*
 @Date: 2022/5/7
 @Desc: 网络请求
 */

import UIKit
import Alamofire



class IPNetworkManager {
    
    static let defalut = IPNetworkManager()
    
    
    /// 请求数据
    func reqeust<T: IPJson>(_ cls: T.Type,router: IPRouter,failure: ((_ desc: String)->Void)?, successful: ((_ obj:T?)->Void)?) {

        do {
            let request = try router.asURLRequest()
            let dataRequest = AF.request(request)
            dataRequest.responseString(encoding: .utf8) { (resp: AFDataResponse<String>) in
                guard let respStr = resp.value else {
                    print("错误信息->未有返回字符串\nApi\(router.path)")
                    failure?("未返回信息")
                    return
                }
                print("--数据-->\(respStr)")
            }
        } catch let error {
            failure?("\(error)")
        }
    }
    
}


